package com.sq.partner.manager.dao.impl;

import java.math.BigDecimal;
import java.sql.Connection;
import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Repository;

import com.sq.partner.manager.dao.IGatewayOrderDao;
import com.sq.partner.manager.mybatis.model.GatewayPolicy;
import com.sq.partner.manager.mybatis.model.TreeDto;
import com.sq.partner.manager.util.DecimalUtil;
import com.sq.partner.manager.util.Page;
import com.sq.partner.manager.util.StrUtil;
@Repository
public class GatewayOrderDaoImpl extends BaseDaoImpl implements IGatewayOrderDao {

	@Override
	public Page<Map<String, Object>> queryOrderPageByCriteria(
			Page<Map<String, Object>> page) throws Exception {
		Map<String,Object> map = (Map<String, Object>) page.getType();
		Object obj = query("getOrderTotalCount", map);
		int total = 0;
		if(null!=obj){
			total = Integer.parseInt(obj.toString()); 
		}

		@SuppressWarnings("unchecked")
		List<Map<String,Object>> list = queryList("getOrderPage", map);
		if(null==list){
			list = new ArrayList<Map<String,Object>>();
		}
		
		page.setTotal(total);
		page.setData(list);
		
		return page;
	}

	@Override
	public Page<Map<String, Object>> queryPolicyPageByOrderNo(Page<Map<String, Object>> page)
			throws Exception {
		Map<String,Object> map = (Map<String, Object>) page.getType();
		Object obj = query("queryPolicyCountByOrderId", map);
		int total = 0;
		if(null!=obj){
			total = Integer.parseInt(obj.toString()); 
		}

		@SuppressWarnings("unchecked")
		List<Map<String,Object>> list = queryList("queryPolicyPageByOrderId", map);
		if(null==list){
			list = new ArrayList<Map<String,Object>>();
		}
		
		page.setTotal(total);
		page.setData(list);
		
		return page;
	}

	@Override
	public List<TreeDto> querySubChannelTreeByParentChannelCode(
			String parentChannelCode) throws Exception {
		
		return queryList("querySubChannelTreeByParentChannelCode", parentChannelCode);
	}
}
